package com.dcy.znoa.controller.publiz.model;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import lombok.*;

/**
 * Created by pengyu on 2017/10/23.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SelectBaseModel {


    //    @DecimalMin("1")
    int pageNum;//从1开始
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    int beginSize;//从1开始
    //    @DecimalMin("1")
    @Setter(AccessLevel.NONE)
    int pageSize = 999999;//大于0, 默认20

    public int getBeginSize() {
        beginSize = (pageNum -1) * pageSize;
        return beginSize;
    }

    public void setBeginSize(int beginSize) {
        this.beginSize = (pageNum -1) * pageSize;
    }

    public void setPageSize(int pageSize) {
        if (pageSize > 0) {
            this.pageSize = pageSize;
        }
    }

    public static void PageFill(SelectBaseModel model ,EntityWrapper ew){
        if(model.getPageNum()>0 && model.getPageSize() >0){
            Page page  =new Page(model.getPageNum(),model.getPageSize());
            SqlHelper.fillWrapper(page,ew);
        }
    }
    //查询分页总数,并加上分页条件查询
    public static Integer PageFill(SelectBaseModel model , EntityWrapper ew, BaseMapper baseMapper){
        if(model.getPageNum()>0 && model.getPageSize() >0){
            Integer total = baseMapper.selectCount(ew);
            Page page  =new Page(model.getPageNum(),model.getPageSize());
                SqlHelper.fillWrapper(page,ew);
            return total;
        }
        return null;
    }
//    public int getPageNum() {
//        return pageNum;
//    }
//
//    public void setPageNum(int pageNum) {
//        this.pageNum = pageNum;
//    }
//
//    public int getPageSize() {
//        return pageSize;
//    }
//
//    public void setPageSize(int pageSize) {
//        this.pageSize = pageSize;
//    }


}
